package o;

import android.content.Context;
import android.content.Intent;
import android.content.pm.IPackageDeleteObserver;
import android.content.pm.PackageManager;
import android.os.Build.VERSION;
import android.os.Message;
import com.huawei.appgallery.packagemanager.api.bean.ManagerTask;
import com.huawei.appgallery.packagemanager.impl.uninstall.control.PackageUninstallObserver;
import com.huawei.appgallery.packagemanager.impl.uninstall.process.PackageUninstallerActivity;

public abstract class cpy {
    public static void ˎ(Context context, ManagerTask managerTask) {
        managerTask.status = cnz.UNINSTALLING;
        if ((managerTask.flag & 1) == 1) {
            if (!ˏ(context, managerTask)) {
                managerTask.status = cnz.NOT_HANDLER;
                if ((managerTask.flag & 2) == 2) {
                    ॱ(context, managerTask);
                } else {
                    ˊ(context, managerTask);
                }
            }
        } else if ((managerTask.flag & 2) == 2) {
            ॱ(context, managerTask);
        } else {
            managerTask.status = cnz.NOT_HANDLER;
            cnu.ˏ.ˋ("UnInstallProcess", "can not find any uninstall type for your task," + managerTask.packageName);
            cph.ॱ(context).ˋ(managerTask.packageName, 6, cnz.NOT_HANDLER, -10004, 5, managerTask.taskId, cod.UNINSTALL);
        }
    }

    private static void ॱ(Context context, ManagerTask managerTask) {
        cnu.ˏ.ˋ("UnInstallProcess", "systemUninstall begin,task:" + managerTask.packageName);
        try {
            Intent intent = new Intent(context, PackageUninstallerActivity.class);
            intent.putExtra("uninstall_packagename", managerTask.packageName);
            intent.putExtra("uninstall_for_all_user", managerTask.uninstallForAllUser);
            intent.putExtra("uninstall_taskId", managerTask.taskId);
            intent.setFlags(402653184);
            Message obtainMessage = cov.ˏ(context).obtainMessage();
            obtainMessage.what = managerTask.packageName.hashCode();
            obtainMessage.obj = managerTask;
            cov.ˏ(context).sendMessageDelayed(obtainMessage, 5000);
            context.startActivity(intent);
        } catch (Throwable e) {
            cnu.ˏ.ˊ("UnInstallProcess", "can not start uninstall !", e);
            ˊ(context, managerTask);
        }
    }

    public static void ˊ(Context context, ManagerTask managerTask) {
        cnu.ˏ.ˋ("UnInstallProcess", "startPackageUninstallerActivityFailed pkg :" + managerTask.packageName + ",returnCode:" + -5);
        cph.ॱ(context).ˋ(managerTask.packageName, 9, cnz.NOT_HANDLER, -5, 5, managerTask.taskId, cod.UNINSTALL);
    }

    private static boolean ˏ(Context context, ManagerTask managerTask) {
        int i = 2;
        cnu.ˏ.ˋ("UnInstallProcess", "innerUninstall begin!! task:" + managerTask.packageName);
        if (cpb.ˎ(context)) {
            if (!managerTask.uninstallForAllUser) {
                i = 0;
            }
            try {
                PackageUninstallObserver packageUninstallObserver = new PackageUninstallObserver(context, managerTask);
                PackageManager packageManager = context.getPackageManager();
                if (VERSION.SDK_INT >= 26) {
                    cpx.ˏ(context, managerTask);
                } else {
                    PackageManager.class.getMethod("deletePackage", new Class[]{String.class, IPackageDeleteObserver.class, Integer.TYPE}).invoke(packageManager, new Object[]{managerTask.packageName, packageUninstallObserver, Integer.valueOf(i)});
                }
                cnu.ˏ.ˋ("UnInstallProcess", "innerUninstall end!" + managerTask.packageName);
                return true;
            } catch (Throwable e) {
                cnu.ˏ.ˊ("UnInstallProcess", "innerUninstall IllegalArgumentException", e);
                cnu.ˏ.ˊ("UnInstallProcess", "innerUninstall failed!!!!!!!");
                return false;
            } catch (Throwable e2) {
                cnu.ˏ.ˊ("UnInstallProcess", "innerUninstall exception: ", e2);
                cnu.ˏ.ˊ("UnInstallProcess", "innerUninstall failed!!!!!!!");
                return false;
            }
        }
        cnu.ˏ.ˊ("UnInstallProcess", "UnInstallProcess" + " can not inner innerUninstall!pkg:" + managerTask.packageName);
        return false;
    }
}
